using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.ComponentModel;
using System.Drawing.Design;
using System.Configuration;
using LibreriaCommon; 

namespace LibreriaWC
{
	/// <summary>
	/// Clase que extiende al control LinkButton.
	/// </summary>
    [ToolboxData("<{0}:lbBase runat=server></{0}:lbBase>")] 
	public class lbBase : System.Web.UI.WebControls.LinkButton
	{
        protected override void OnPreRender(EventArgs e)
        {
            base.OnPreRender(e);

            if (ConfigurationManager.AppSettings["ValidadoresExtendidos"] != null &&
                ConfigurationManager.AppSettings["ValidadoresExtendidos"] == "true" &&
                this.CausesValidation &&
                Page.Validators != null)
            {
                int i = 0;

                while (i < Page.Validators.Count &&
                        ((BaseValidator)Page.Validators[i]).ValidationGroup != this.ValidationGroup &&
                        ((BaseValidator)Page.Validators[i]).Enabled &&
                        ((BaseValidator)Page.Validators[i]).Visible)
                {
                    i++;
                }

                if (i < Page.Validators.Count)
                {
                    this.Attributes.Add("onclick", "javascript: if (typeof(WebForm_DoPostBackWithOptionsMio) == 'function') { WebForm_DoPostBackWithOptionsMio(new WebForm_PostBackOptions('" + ClientID + "', '', true, '" + this.ValidationGroup + "', '" + this.PostBackUrl + "', false, true)); }");
                }
            }

            if (VerificarPresionado)
                this.OnClientClick = "javascript: if (!presionado) { presionado = true; return true; } else { alert('Un momento por favor...'); return false; }";
        }

        [DefaultValue(false)]
        [Localizable(false)]
        [Bindable(false)]
        public bool VerificarPresionado
        {
            get
            {
                if (ViewState["VerificarPresionado"] != null)
                    return Convert.ToBoolean(ViewState["VerificarPresionado"]);
                else
                    return false;
            }
            set
            {
                ViewState.Add("VerificarPresionado", value);
            }
        }
	}
}